package com.lhczf.lucenedb.consumer;

import com.lhczf.lucenedb.bean.AuditDataConfig;
import com.lhczf.lucenedb.bean.DataWrap;
import com.lhczf.lucenedb.util.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author: 刘华春
 * @date: 2019/2/6
 */
@Slf4j
public class AuditDataConsumer extends AbstractDataConsumer<String> {

    private static final String INDEX_NAME = "audit_record";

    @Override
    public String configIndexName() {
        return INDEX_NAME;
    }

    @Override
    AbstractDataConsumer<String> createDataConsumer() {
        return new AuditDataConsumer();
    }

    @Override
    public boolean autoRecover() {
        return true;
    }

    @Override
    public void configTaxoIndexWriter(DirectoryTaxonomyWriter taxonomyWriter) {
        TAXONOMY_WRITER_MAP.putIfAbsent(INDEX_NAME, taxonomyWriter);
    }

    @Override
    public int runtimeThreadNum() {
        return BeanUtil.getInstance().getBean(AuditDataConfig.class).getRunThreadNum();
    }

    @Override
    public boolean hasConfigTaxoWriter() {
        return true;
    }
    @Override
    DataWrap takeDataWrap() {
        BlockingQueue blockingQueue = DATA_QUEUE.computeIfAbsent(INDEX_NAME, k -> new LinkedBlockingQueue());
        return getDataWrapFromQueue(blockingQueue);
    }
}
